﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CarRental.Control.Cars
{
    using CarRental.ViewModel;
    using Database;

    public partial class CarView : System.Web.UI.UserControl
    {
        public CarViewModel Car { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["id"] != null)
            {
                int carId = Int32.Parse(Request.QueryString["id"]);
                var car = Database.GetCar(carId);

                this.Car = new CarViewModel
                {
                    ModelName = car.Model.ModelName,
                    ProducerName = car.Producer.ProducerName,
                    ProductionYear = car.ProductionYear,
                    Images = car.Images
                };
            }

            else
            {
                Response.Redirect("/");
            }
        }
    }
}